<%@ page contentType="text/html; charset=utf-8"%>

<div id="userUrlDiv" style="width: 1168px; display: none;">
	<div class="infoDiv">
		<div class="infoHead">
			<h3 style="margin-top: 5px; margin-left: 10px;">网页测试配置</h3>
		</div>

	<div style="height: 50px;">
	
		<table style="float: left;" >
			<tr>
				<td style="text-align: right;padding-left: 20px;"><span>每个URL测试次数：</span>
				</td>
				<td><input id="webTestNumber" style="width: 200px;height: 25px;margin-top: 5px;" type="text"
					size="50">
				</td>

				<td style="text-align: right;"><input
					class="btn btn-primary m_r" onclick="updateWebTestNumber()" style="height: 35px;width: 100px;margin-left: 20px;"
					type="button" value="修改 ">
				</td>
			</tr>
		
		</table>
	
		<input type="button" id="addUrlBtn" onclick="addUrl(0)"
			style="width: 100px; float: right;margin-top: 5px;height: 35px;" class="btn btn-primary m_r"
			value="添加URL"></input>
	</div>
	<div id="userTableDiv">
		<table class="table table-striped table-bordered" id="urlsTable"></table>
	</div>
	<div id="addUrlDiv" style="display: none;">
		<table >
			<tr>
				<td style="text-align: right;"><span>URL：</span>
				</td>
				<td><input id="addUrlAddress" style="width: 300px;height: 25px;margin-top: 5px;" type="text"
					size="50">
				</td>

				<td style="text-align: right;"><input
					class="btn btn-primary m_r" onclick="saveOrUpdateUrl()" style="height: 35px;width: 100px;margin-left: 20px;"
					type="button" value="保存 ">
				</td>
			</tr>
		
		</table>

	</div>



	</div>
	
		<div class="infoDiv">
		<div class="infoHead">
			<h3 style="margin-top: 5px; margin-left: 10px;">下载测试配置</h3>
		</div>

	<div style="height: 50px;">
	
		<table style="float: left;" >
			<tr>
				<td style="text-align: right;padding-left: 20px;"><span>测试文件地址：</span>
				</td>
				<td><input id="downFileTestUrl" style="width: 400px;height: 25px;margin-top: 5px;" type="text"
					size="50">
				</td>

				<td style="text-align: right;"><input
					class="btn btn-primary m_r" onclick="updateDownFileTestUrl()" style="height: 35px;width: 100px;margin-left: 20px;"
					type="button" value="修改 ">（形式如同www.baidu.com 请不要在url地址上添加引号）
				</td>
			</tr>
		
		</table>
	
	
	</div>

	</div>
	
</div>


<script type="text/javascript">
	
	var urlData;
	var updateUrlBean;
	var updateOrSaveUrl;
	
	$(function() {
		getUrls();
		getWebTestNumber();
		getDownFileUrl();
		
	});
	
	function getDownFileUrl() {
		$.post("userUrl", {
			"types" : "getDownFileUrl"
		}, function(data) {

			if (data != null) {
	
				 $("#downFileTestUrl").val(data);
			
			}
		}, "json");
	}
		
	function getWebTestNumber(){
		
		$.post("userUrl", {"types":"getWebTestNumber"},
				   function(data){
						$("#webTestNumber").val(data);
				   },"json");
		
	}
	
	
		function getUrls(){
			$.post("userUrl", {"types":"getUrls"},
					   function(data){
							urlData = data;
							setUrlTableData(data);
					   },"json");
		}
	
	function setUrlTableData(data){
		var tableVal = "<thead><tr><th>URL</th><th>操作</th></tr></thead><tbody >";
		for(var i=0;i<data.length;i++){
			var obj = data[i];
			tableVal = tableVal+"<tr><td>"+obj.testUrl+"</td>"+
			"<td><a onclick='updateUrl("+obj.id+")' href='#'>修改</a><a href='#' onclick='delUrl("
					+obj.id+","+i+")' style='margin-left: 20px;'>删除</a></td></tr>";
		}
		tableVal = tableVal+"</tbody>";
		$("#urlsTable").html(tableVal);
	} 
		
		function updateUrl(id){
			for(var i=0;i<urlData.length;i++){
				var obj = urlData[i];
				if(obj.id==id){
					updateUrlBean = obj;
					$("#addUrlAddress").val(obj.testUrl);
					$("#addUrlTestTimes").val(obj.testTimes);
					addUrl(1);
					break;
				}
			}
		}
		
		function saveOrUpdateUrl(){
			if(updateOrSaveUrl==0){
				var urlAddress = $("#addUrlAddress").val();
				var times = $("#addUrlTestTimes").val();
				
				if(urlAddress==""||times==""){
					alert("URL或测试次数不能为空");
					return;
				}
				$.post("userUrl", {"types":"addUrl","testTimes":times,"testUrl":urlAddress},
						   function(data){
						if(data==true){
							getUrls();
							addUrl(3);
						}else{
							alert("URL添加失败");
						}
						   },"json");
				
			}else if(updateOrSaveUrl==1){
				var urlAddress = $("#addUrlAddress").val();
				var times = $("#addUrlTestTimes").val();
				if(urlAddress==""||times==""){
					alert("URL或测试次数不能为空");
					return;
				}
				$.post("userUrl", {"types":"updateUrl","id":updateUrlBean.id,"testTimes":times,"testUrl":urlAddress},
						   function(data){
						if(data==true){
							getUrls();
							addUrl(3);
						}else{
							alert("修改失败");
						}
						   },"json");
			}
			
			
		}
		
		
		
		function delUrl(id,i){
			$.post("userUrl", {"types":"delUrl","id":id},
					   function(data){
				if(data==true){
					urlData.baoremove(i);
					setUrlTableData(urlData);
					}else{
						alert("删除失败");
					}
					   },"json");
		}
		
		
		
		Array.prototype.baoremove = function(dx)
		　{
		　　if(isNaN(dx)||dx>this.length){return false;}
		　　this.splice(dx,1);
		　}
		
		function addUrl(type){
			if(type==0){
				$("#addUrlTestTimes").val("");
				$("#addUrlAddress").val("");
				$("#addUrlDiv").show();
				updateOrSaveUrl=0;
				
				if($("#addUrlBtn").val()=="添加URL"){
					$("#addUrlBtn").val("取消");
					$("#addUrlDiv").show();
				}else{
					$("#addUrlBtn").val("添加URL");
					$("#addUrlDiv").hide();
				}
			}else if(type==1){
				$("#addUrlDiv").show();
				updateOrSaveUrl=1;
				$("#addUrlBtn").val("取消");
				$("#addUrlDiv").show();
			}else{
				
				if($("#addUrlBtn").val()=="添加URL"){
					$("#addUrlBtn").val("取消");
					$("#addUrlDiv").show();
				}else{
					$("#addUrlBtn").val("添加URL");
					$("#addUrlDiv").hide();
				}
				
			}
		
		}
		
		function updateWebTestNumber(){
			
			var 	webTestNumber = $("#webTestNumber").val();
			$.post("userUrl", {"types":"updateWebTestNumber",
				"webTestNumber":webTestNumber},
					   function(data){
							
							if(true==data){
								
								alert("修改成功");
							}
				
					   },"json");
		}
		
		
		function updateDownFileTestUrl(){
			
			var 	downFileTestUrl = $("#downFileTestUrl").val();
			
			$.post("userUrl", {"types":"updateDownFileTestUrl",
				"downFileTestUrl":downFileTestUrl},
					   function(data){
							
							if(true==data){
								
								alert("修改成功");
							}
				
					   },"json");
		}
		
		</script>






